package com.zyq.ssyx.acl.service.impl;

import com.atguigu.ssyx.common.utils.MD5;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyq.ssyx.acl.mapper.AdminMapper;
import com.zyq.ssyx.acl.service.AdminService;
import com.zyq.ssyx.model.acl.Admin;
import com.zyq.ssyx.vo.acl.AdminQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * @author clap of thunder
 * @date 2023-11-27 11:59
 * @description
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    AdminMapper adminMapper;

    @Override
    public IPage selectPage(Page<Admin> adminParam, AdminQueryVo adminQueryVo) {
        String name = adminQueryVo.getName();
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }
//        LambdaQueryWrapper<Admin> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<Admin> wrapper = lambdaQueryWrapper.like(Admin::getName, name);
        //service实现类层中是可以直接调basemapper的
        IPage<Admin> adminIPage = adminMapper.selectPage(adminParam, queryWrapper);
        return adminIPage;
    }

    @Override
    public int safeSave(Admin admin) {
        String password = admin.getPassword();
        String encrypt = MD5.encrypt(password);
        admin.setPassword(encrypt);
        return baseMapper.insert(admin);
    }

}
